//package spitter.controller;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.servlet.mvc.support.RedirectAttributes;
//import spitter.User;
//
//import javax.sql.DataSource;
//import java.io.IOException;
//import java.sql.Connection;
//import java.sql.PreparedStatement;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//
//@Controller
//@RequestMapping("/user")
//public class UserController {
//
//    @Autowired
//    private DataSource dataSource;
//
//    @RequestMapping(value = "/register", method = RequestMethod.GET)
//    public String showRegisterForm() {
//        return "/user/registerForm";
//    }
//
//    @RequestMapping(value = "/register", method = RequestMethod.POST)
//    public String processRegistration(User user, RedirectAttributes model) throws IOException {
//        Connection connection = null;
//        PreparedStatement preparedStatement = null;
//        try {
//            System.out.println(dataSource);
//            connection = dataSource.getConnection();
//            String sql = "insert into t_user(username,password,enabled) values(?,?,?) ";
//            preparedStatement = connection.prepareStatement(sql);
//            preparedStatement.setString(1, user.getUserName());
//            preparedStatement.setString(2, user.getPassword());
//            preparedStatement.setBoolean(3, true);
//            preparedStatement.executeUpdate(sql);
//        } catch (SQLException e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                connection.close();
//                preparedStatement.close();
//            } catch (SQLException e) {
//                e.printStackTrace();
//            }
//        }
//        model.addAttribute("username", user.getUserName());
//        return "redirect:/user/{username}";
//    }
//
//    @RequestMapping("/{username}")
//    public String spitter(@PathVariable String username, Model model) {
//        Connection connection = null;
//        PreparedStatement preparedStatement = null;
//        User user = null;
//        try {
//            connection = dataSource.getConnection();
//            String sql = "select * from t_user where username=? ";
//            preparedStatement = connection.prepareStatement(sql);
//            preparedStatement.setString(1, username);
//            ResultSet resultSet = preparedStatement.executeQuery(sql);
//            while (resultSet.next()) {
////               String uname = resultSet.getString("username");
////               String passwd =resultSet.getString("password");
////               Integer id = resultSet.getInt("id");
////               Boolean enabled  = resultSet.getBoolean("enabled");;
//                user = (User) resultSet.getObject(1);
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                connection.close();
//                preparedStatement.close();
//            } catch (SQLException e) {
//                e.printStackTrace();
//            }
//        }
//        model.addAttribute("user",user);
//        return "/user/userInfo";
//    }
//
//
//}
